package org.jeecg.common.modules.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.modules.inquiry.entity.InquiryInfo;
import org.jeecg.common.modules.order.entity.OrderInfoLog;
import org.jeecg.common.modules.order.mapper.OrderInfoLogMapper;
import org.jeecg.common.modules.order.service.IOrderInfoLogService;
import org.jeecg.common.util.enums.OrderInfoLogTypeEnum;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Description: order
 * @Author: jeecg-boot
 * @Date:   2020-08-26
 * @Version: V1.0
 */
@Service
public class OrderInfoLogServiceImpl extends ServiceImpl<OrderInfoLogMapper, OrderInfoLog> implements IOrderInfoLogService {


    @Override
    public void addLog(String orderId, OrderInfoLogTypeEnum type, String... args) {
        OrderInfoLog log = new OrderInfoLog();
        log.setOrderInfoId(orderId);
        log.setCreateTime(new Date());
        log.setContent(String.format(type.getTemplate(), args));
        save(log);
    }

    @Override
    public List<OrderInfoLog> getLogs(String orderInfoId){
        LambdaQueryWrapper<OrderInfoLog> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(OrderInfoLog::getOrderInfoId,orderInfoId);
        return list(queryWrapper);
    }
}
